package com.lb.utils;

import org.apache.commons.lang3.RandomStringUtils;

/**
 * @version 1.0
 * @Author: Edward
 * @Date: 2021/4/7 9:18
 * @Description:
 */
public class RandomUtils {
    private static String randString = "";
    public synchronized static String getNo(int k) {
        if (randString.length() > 20000) {
            randString = "";
        }
        String rno = getNoNo(k);
        while (randString.indexOf(rno + ",") >= 0) {
            rno = getNoNo(k);
        }
        randString += rno + ",";
        return rno;
    }

    private static String getNoNo(int k) {
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return RandomStringUtils.randomNumeric(k);
    }
}
